package com.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

  /**
   *  AbstractAnnotationConfigDispatcherServletInitializer父类AbstractDispatcherServletInitializer的onStartup方法默认会调用它父类AbstractContextLoaderInitializer#onStartup方法
   *  方法中会执行registerContextLoaderListener(servletContext)进行加载根spring上下文，如项目中只需要controller层可以对父类的onStartup方法进行重写
   *  注意：如下方式重写后则重写{@link #getRootConfigClasses()}就无意义了
  @Override
  public void onStartup(ServletContext servletContext) {
    //注释调用父雷onStartup方法创建根spring上下文
    //super.onStartup();
    registerDispatcherServlet(servletContext);
  }
   */

  @Override
  protected Class<?>[] getRootConfigClasses() {
    return new Class<?>[] {RootConfig.class};
  }

  @Override
  protected Class<?>[] getServletConfigClasses() {
    //添加controller中的bean
    return new Class<?>[] { WebConfig.class };
  }

  @Override
  protected String[] getServletMappings() {
    return new String[] { "*.do" };
  }

}